<template>
	<view class="content b-t">
		<empty v-if="communityList.length === 0"></empty>
		<view class="list b-b" v-for="(item, index) in communityList" :key="index" @click="checkCommunity(item)">
			<view class="wrapper">
				<view class="left-box">
					<view class="address-box">
						<text class="address">{{item.currCommunityInfo.areaName}}</text>
					</view>
					<view class="u-box">
						<text class="name">小区编码：</text>
						<text>{{item.currCommunityInfo.areaCode}}</text>
					</view>
				</view>
				<view class="right-box">
					<text v-if="item.state == '1001'" class="tag">当前小区</text>
				</view>
			</view>
		</view>
		<view class="page-bottom" @click="toExamineRecord()">
			审核记录
		</view>
	</view>
</template>

<script>
	import empty from "@/components/empty";
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			empty
		},
		data() {
			return {
				communityList: [],
				currCommunityId: this.$api.util.getAreaCode(),
			}
		},
		onLoad(option) {
			this.inquiryCommunity()
		},
		onShow() {
			// console.log(this.userInfo.userUuid)
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			change(open) {
				console.log('当前开启状态：' + open)
			},
			//选择地址
			checkCommunity(item) {
				console.log(item)
				let that = this;
				this.$api.request.updateCurrCommunityUser({
					currCommunityId: that.currCommunityId,
					updateCommunityId: item.id
				}, res => {
					if (res.body.status.statusCode === '0') {
						this.afterBind(item)
					} else {
						this.$api.msg(res.body.status.errorDesc);
					}
				})
			},
			afterBind(item) {
				console.log(item)
				uni.setStorageSync('bindCommunityInfo', item);
				this.$api.msg("切换成功");
				uni.navigateBack()
			},
			//查询当前用户绑定乡村
			inquiryCommunity() {
				this.$api.request.getCommunityByUserInfo({
					userId: this.userInfo.userUuid
				}, res => {
					if (res.body.status.statusCode === '0') {
						this.communityList = res.body.data.communityUserEntities;
					} else {
						this.$api.msg(res.body.status.errorDesc);
					}
				});
			},
			toExamineRecord() {
				uni.navigateTo({
					url: "/package_mall/pages/user/examineRecord"
				})
			}
		}
	}
</script>

<style lang='scss'>
	page {
		padding-bottom: 120upx;
	}

	.content {
		position: relative;
	}

	.list {
		display: flex;
		align-items: center;
		padding: 20upx 30upx;
		;
		background: #fff;
		position: relative;
	}

	.wrapper {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		width: 100%
	}

	.left-box {}

	.right-box {}

	.tag {
		font-size: 24upx;
		color: $base-color;
		margin-right: 10upx;
		background: #fffafb;
		border: 1px solid #ffb4c7;
		border-radius: 4upx;
		padding: 5upx 10upx;
		line-height: 1;
	}

	.address-box {
		display: flex;
		align-items: center;



		.address {
			font-size: 30upx;
			color: $font-color-dark;
		}
	}

	.u-box {
		font-size: 28upx;
		color: $font-color-light;
		margin-top: 16upx;

		.name {
			margin-right: 10upx;
		}
	}

	.icon-bianji {
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 40upx;
		color: $font-color-light;
		padding-left: 30upx;
	}

	.add-btn {
		position: fixed;
		left: 30upx;
		right: 30upx;
		bottom: 16upx;
		z-index: 95;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		font-size: 32upx;
		color: #fff;
		background-color: $base-color;
		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}

	/* 底部操作菜单 */
	.page-bottom {
		position: fixed;
		left: 30upx;
		bottom: 30upx;
		z-index: 95;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 690upx;
		height: 100upx;
		color: #FFFFFF;
		font-size: 34upx;
		letter-spacing: 2upx;
		background: linear-gradient(to right, #ffac30, #fa436a, #F56C6C);
		box-shadow: 0 0 20upx 0 rgba(0, 0, 0, .5);
		border-radius: 16upx;
	}
</style>
